/*Check  date valid 
*@param dateStr : String neeed to process
*@return true if dateStr is date format else return false
*/
function fnsCheckIsDateVN(dateStr){
	var datePat = /^(\d{1,2})(-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (dateStr=='')return false;
	if (matchArray == null) return false;
	
	month = matchArray[3]; // parse date into variables
	day = matchArray[1];
	year = matchArray[5];
	
	if (day < 1 || day > 31)return false;
	if (month < 1 || month > 12) return false;
	if ((month==4 || month==6 || month==9 || month==11) && (day==31)) return false;
	if (month == 2){ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		
		if (day > 29 || (day==29 && !isleap)) return false; 
	}
	if ((year<1900) || (year>2099)) return false;
	return true; // date is valid
}

function fnsCheckDate(from_ngay,to_ngay) {	
	if (from_ngay == "" || to_ngay == "") return true;
	var arrDate1;
	var arrDate2;
	arrDate1 = from_ngay.split("-");
	arrDate2 = to_ngay.split("-");
	
	if (arrDate1[1].length == 1) arrDate1[1]= "0" + arrDate1[1];
	if (arrDate1[0].length == 1) arrDate1[0]= "0" + arrDate1[0];
	if (arrDate2[1].length == 1) arrDate2[1]= "0" + arrDate2[1];
	if (arrDate2[0].length == 1) arrDate2[0]= "0" + arrDate2[0];
	
	var strDate1 = arrDate1[2] + arrDate1[1] + arrDate1[0];
	var strDate2 = arrDate2[2] + arrDate2[1] + arrDate2[0];
	if (strDate1 <= strDate2) return true;
	else return false;
}
/*Check  Email valid 
*@param email : String neeed to process
*@return true if email is email format else return false
*/
function fnsCheckIsEmail(email){	
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else			
		return false;
}
/*Function numeric of Integer
*@param str :string need to process
*@return tru if string is number format else return false
*/
			function fnsCheckNumInt (str)
			{
				var ch = str.substring(0,1);
				if ((ch != '+') && (ch != '-') && (ch < "0" || ch > "9"))
					{
					return "false";
					}
				else 
					{
					var count = 0;
					var count1 = 0;
					for (var i = 1; i < str.length;i++)
						{
						var ch1 = str.substring(i,i + 1);
						if ((ch1 < "0" || ch1 > "9") && (ch1 != '.'))
							{
							count = count + 1;
							}
						if (ch1 == '.')
							{
							count1 = count1 + 1;
							}
						}
					if ((count == 0) && (count1 == 0))
						{
						return "true";
						}
					else {return "false";}
					}
			}

/*Function check numeric of Float
* @param str : string need to process
* @resutn true if str is float format else return false
*/

			function fnsCheckNumFloat (str)
			{
				var ch = str.substring(0,1);
				if ((ch != '+') && (ch != '-') && (ch < "0" || ch > "9"))
					{
					return "false";
					}
				else 
					{
					var count = 0;
					var count1 = 0;
					for (var i = 1; i < str.length;i++)
						{
						var ch1 = str.substring(i,i + 1);
						if ((ch1 < "0" || ch1 > "9") && (ch1 != '.'))
							{
							count = count + 1;
							}
						if (ch1 == '.')
							{
							count1 = count1 + 1;
							}
						}
					if ((count == 0) && (count1 <= 1))
						{
						return "true";
						}
					else {return "false";}
					}
			}
			
/*Function check numeric of Alpha Numeric
* @param alpha : string need to process
* @resutn true if str is alpha numeric format else return false
*/
					function fnsCheckNumAlpha(alpha)
					{
					var testalpha = /^[A-Za-z0-9]{0,20}$/;
					var chkalpha = alpha;
						if (testalpha.test(chkalpha))
							{
							return true;
							}
						else return false;
					}	